package www.admin.service.impl;

import java.math.BigDecimal;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import www.admin.dao.IBorrowLogDao;
import www.admin.model.BorrowLog;
import www.admin.mybatis.Criteria;
import www.admin.service.IBorrowLogService;
import www.admin.utils.Layui;
import www.admin.utils.MessageConstant;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

/**
 * 
 * BorrowLog
 * 
 **/

@Service
public class BorrowLogServiceImpl implements IBorrowLogService{


	public Layui queryPage (Criteria<BorrowLog> param){
		PageHelper.startPage(param.getStartIndex(), param.getPageSize());
		List<BorrowLog> list = borrowLogRepository.queryPage(param);
		Double sumMoney = borrowLogRepository.querySumMoney(String.valueOf(param.getParams().get("borrow_id")));
		if (sumMoney != null) {
			list.get(0).setSumMoney(new BigDecimal(sumMoney));
		}
		PageInfo<BorrowLog> paInfo = new PageInfo<BorrowLog>(list);
	return Layui.data((int)paInfo.getTotal(), paInfo.getList()); }

	public Integer queryPageCount (Criteria<BorrowLog> param){
		return (Integer) borrowLogRepository.queryPageCount(param);
	}

	public BorrowLog  queryEntity (String id ){
		return borrowLogRepository.queryEntity(id);
	}

	public String deleteById (String id ){
		int result = borrowLogRepository.deleteById(id);
			if ( result != 1) {
					return MessageConstant.USER_TYPE_3;
			}
			return null;
	}

	public String insert(BorrowLog record ){
		int result = borrowLogRepository.insert(record);
			if ( result != 1) { 
					return MessageConstant.USER_TYPE_4;
			}
			return null;
	}

	public String update (Criteria<BorrowLog> param){
		int result = borrowLogRepository.update(param);
			if ( result != 1) { 
					return MessageConstant.USER_TYPE_5;
			}
			return null;
	}

	@Resource
	private IBorrowLogDao borrowLogRepository;
	
}